package com.pwt.controller.basicsetting;

import com.pwt.annotation.Update;
import com.pwt.common.CustomException;
import com.pwt.common.Result;
import com.pwt.common.ResultCode;
import com.pwt.common.ResultPage;
import com.pwt.entity.ProductFeature;
import com.pwt.model.FeatureModel;
import com.pwt.service.ProductFeatureService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/8/30
 */
@RestController
@Tag(name = "设置-检测特征")
public class ProductFeatureController {

    private ProductFeatureService productFeatureService;

    /**
     * 构造注入
     * @param productFeatureService
     */
    public ProductFeatureController(ProductFeatureService productFeatureService){
        this.productFeatureService = productFeatureService;
    }

    @GetMapping("/features")
    @Operation(description = "检测特征列表查询",summary = "检测特征列表查询")
    @Parameters({
            @Parameter(name = "name",description = "检测特征名称",required = false),
            @Parameter(name = "page",description = "分页数",required = true),
            @Parameter(name = "limit",description = "展示数",required = true)
    })
    public ResultPage<FeatureModel> getFeatures(@RequestParam(value = "name",required = false) String name, @RequestParam(value = "page",required = true) Integer page, @RequestParam(value = "limit",required = true) Integer limit){
        return this.productFeatureService.getFeatures(name,page,limit);
    }

//    @PostMapping("/feature")
//    @Operation(description = "新增检测特征对象",summary = "新增检测特征对象")
//    public ProductFeature  add(@RequestBody @Validated ProductFeature productFeature){
//        return this.productFeatureService.add(productFeature);
//    }
//
//    @GetMapping("/feature/query/{id}")
//    @Operation(description = "根据id查询检测特征对象",summary = "根据id查询检测特征对象")
//    public ProductFeature  getById(@Parameter(name = "id",description = "数据id",required = true) @PathVariable("id") String id){
//        return this.productFeatureService.getById(id);
//    }
//
//
//    @PutMapping("/feature")
//    @Operation(description = "修改检测特征对象",summary = "修改检测特征对象")
//    public ProductFeature  update(@RequestBody @Validated(value = Update.class) ProductFeature productFeature) throws CustomException {
//        if(StringUtils.isBlank(productFeature.getId())){
//            throw new CustomException(ResultCode.PARAM_IS_BLANk);
//        }
//        return this.productFeatureService.add(productFeature);
//    }
//
//    @DeleteMapping("/feature/{id}")
//    @Operation(description = "根据id删除检测特征对象",summary = "根据id删除检测特征对象")
//    public void  delete(@Parameter(name = "id",description = "数据id",required = true) String id){
//        this.productFeatureService.delete(id);
//    }
}
